﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;

namespace Twitter.Tests
{
    [TestFixture]
    public class MessageTextNormalizerFixture
    {
        [Test]
        public void NormalizerTrimsMessageText()
        {
            Message m = new Message();
            m.Text = "   abc   ";

            MessageTextNormalizer normalizer = new MessageTextNormalizer();
            normalizer.NormalizeWhitespaceAndCasing(m);

            Assert.AreEqual("abc", m.Text);
        }

        [Test]
        public void NormalizerLowersCapitalizationOfMessageText()
        {
            Message m = new Message();
            m.Text = "AbC";

            MessageTextNormalizer normalizer = new MessageTextNormalizer();
            normalizer.NormalizeWhitespaceAndCasing(m);

            Assert.AreEqual("abc", m.Text);
        }


        [Test]
        public void NormalizerTurnsNewLinesInSpaces()
        {
            Message m = new Message();
            m.Text = "A\nbC";

            MessageTextNormalizer normalizer = new MessageTextNormalizer();
            normalizer.NormalizeWhitespaceAndCasing(m);

            Assert.AreEqual("a bc", m.Text);
        }

        [Test]
        public void NormalizerTurnsTabsInSpaces()
        {
            Message m = new Message();
            m.Text = "A\tbC";

            MessageTextNormalizer normalizer = new MessageTextNormalizer();
            normalizer.NormalizeWhitespaceAndCasing(m);

            Assert.AreEqual("a bc", m.Text);
        }

        [Test]
        public void NormalizerMakesASingleSpaceOutofManySpaces()
        {
            Message m = new Message();
            m.Text = "A    bC";

            MessageTextNormalizer normalizer = new MessageTextNormalizer();
            normalizer.NormalizeWhitespaceAndCasing(m);

            Assert.AreEqual("a bc", m.Text);
        }

        [Test]
        public void NormalizerMakesASingleSpaceOutofDifferentWhitespace()
        {
            Message m = new Message();
            m.Text = "A \n \t " + new string((char)13, 1) + " b" + new string((char)10, 1) + "C";

            MessageTextNormalizer normalizer = new MessageTextNormalizer();
            normalizer.NormalizeWhitespaceAndCasing(m);

            Assert.AreEqual("a b c", m.Text);
        }

        [Test]
        public void NormalizerRespectsQuestionMarks()
        {
            Message m = new Message();
            m.Text = "?";

            MessageTextNormalizer normalizer = new MessageTextNormalizer();
            normalizer.NormalizeWhitespaceAndCasing(m);

            Assert.AreEqual("?", m.Text);
        }
    }
}
